{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WZ1G8QHhdHZR"
   },
   "source": [
    "##### Copyright 2020 The Cirq Developers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form",
    "id": "KQa9t_gadIuR"
   },
   "outputs": [],
   "source": [
    "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "# https://www.apache.org/licenses/LICENSE-2.0\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "xwec7FrkdFmi"
   },
   "source": [
    "# Qubits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "5KZia7jmdJ3V"
   },
   "source": [
    "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
    "  <td>\n",
    "    <a target=\"_blank\" href=\"https://www.example.org/cirq/gates\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on QuantumLib</a>\n",
    "  </td>\n",
    "  <td>\n",
    "    <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/master/docs/gates.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
    "  </td>\n",
    "  <td>\n",
    "    <a target=\"_blank\" href=\"https://github.com/quantumlib/Cirq/blob/master/docs/gates.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
    "  </td>\n",
    "  <td>\n",
    "    <a href=\"https://storage.googleapis.com/tensorflow_docs/Cirq/docs/gates.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Download notebook</a>\n",
    "  </td>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "bd9529db1c0b"
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    import cirq\n",
    "except ImportError:\n",
    "    print(\"installing cirq...\")\n",
    "    !pip install --quiet cirq\n",
    "    print(\"installed cirq.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "y8P1T6duC-yo"
   },
   "source": [
    "A qubit is the basic unit of quantum information, a quantum bit: a two level system that can exist in superposition of those two possible states. Cirq also supports higher dimensional systems, so called [qudits](qudits.ipynb) that we won't cover here.\n",
    "\n",
    "In Cirq, a `Qubit` is nothing else than an abstract object that has an identifier, a `cirq.Qid` and some other potential metadata to represent device specific properties that can be used to validate a circuit.\n",
    "In contrast to real qubits, the Cirq qubit does not have any state. The reason for this is that the actual state of the qubit or qubits is maintained in the quantum processor, or, in case of simulation, in the simulated state vector."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "-Gbg8dEJDH4D"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "myqubit: ───H───\n",
      "result:\n",
      "measurements: (no measurements)\n",
      "output vector: 0.707|0⟩ + 0.707|1⟩\n"
     ]
    }
   ],
   "source": [
    "import cirq\n",
    "\n",
    "qubit = cirq.NamedQubit(\"myqubit\")\n",
    "\n",
    "# creates an equal superposition of |0> and |1> when simulated\n",
    "circuit = cirq.Circuit(cirq.H(qubit))\n",
    "\n",
    "# see the \"myqubit\" identifier at the left of the circuit\n",
    "print(circuit)\n",
    "\n",
    "# run simulation\n",
    "result = cirq.Simulator().simulate(circuit)\n",
    "\n",
    "print(\"result:\")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8ee194281125"
   },
   "source": [
    "### Qubit types\n",
    "\n",
    "There are 3 main qubit types in Cirq:\n",
    "\n",
    "- `cirq.NamedQubit` - an abstract qubit that only has a name, nothing else. Use this when you don't need anything else and you don't need to create too many qubits in bulk.\n",
    "- `cirq.LineQubit` - a qubit that is identified by an integer index in a line. Some devices have lines of qubits, `LineQubit` can be useful to represent that. Also `cirq.LineQubit.range(3)` is a very easy way to create 3 qubits.  \n",
    "- `cirq.GridQubit` - a qubit that is placed on a grid and is identified by the 2D coordinates. Most of Google's chips are represented using `GridQubit`s. \n",
    "\n",
    "Some providers provide their own qubit types. For example Pasqal defines a `TwoDQubit` and a `ThreeDQubit` to represent the specific topology of neutral atoms when validating circuits.\n"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [
    "Sh9QBnKbFf_B"
   ],
   "name": "qubits.ipynb",
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
